﻿using System;
public class Program
{
    public class Node<T>
    {
        public Node<T> Next { get; set; }
        public T Data { get; set; }
        public Node(T t)
        {
            Next = null;
            Data = t;
        }
    }
    public class GenericList<T>
    {
        
        public Node<T> head;
        public Node<T> tail;
        public GenericList()
        {
            head = tail = null;
        }
        public Node<T> Head
        {
            get => head;
        }

        public Node<T> Tail
        {
            get => tail;
        }
        public void Add(T t)
        {
            Node<T> n = new Node<T>(t);
            if(tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n; 
            }
        }
         
        
        
        
        public void ForEach(GenericList<int> n, Action<Node<int>> action)
        {
            
            for(Node<int> node = n.Head; node != null; node = node.Next)
                action(node);
            
        }
        

    }

    public static void Main(string[] args)
    {
        GenericList<int> intList = new GenericList<int>();
        for(int x = 0;x<10;x++)
        {
            intList.Add(x);
        }
        intList.ForEach(intList, (Node<int> node) => Console.WriteLine(node.Data));
        int max = 0;
        int min = 0;
        int sum = intList.Head.Data;
        intList.ForEach(intList, (Node<int> node) =>
        {
            
            if (node.Next != null)
            {
                int next = node.Next.Data;
                if (next > max)
                    max = next;
                else
                    max = max;
            }
            else
            {
                Console.WriteLine("最大值为"+max);
            }
        });
        intList.ForEach(intList, (Node<int> node) =>
         {
             int pre = node.Data;

             if (node.Next != null)
             {
                 int next = node.Next.Data;
                 if (next < min)
                     min = next;
                 else
                     min = min;
             }
             else
             {
                 Console.WriteLine("最小值为" + min);
             }
         });
        intList.ForEach(intList, (Node<int> node) =>
        {

            if (node.Next != null)
            {
                sum += node.Next.Data;
            }
            else
            {
                Console.WriteLine("和为" + sum);
            }
        });


    }
}